package com.lhy.admin.common.secure.filter;

import com.lhy.admin.common.secure.SecureValidator;
import com.lhy.admin.common.secure.authorization.PermissionLogicalValidator;
import com.lhy.admin.common.secure.exception.UnAuthorizedException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.method.HandlerMethod;

import javax.servlet.http.HttpServletRequest;

/**
 * @author hyluan
 * @ClassName: AuthorizationInterceptor
 * @Description: 权限控制器
 * @date 2018/4/10 9:26
 * @Copyright: Copyright (c) 2018 wisedu
 */
@Slf4j
public class AuthorizationInterceptor extends HandlerMethodInterceptor {

    private SecureValidator validator = new PermissionLogicalValidator();

    @Override
    protected void handleMethod(HttpServletRequest request, HandlerMethod handlerMethod) {
        if (!validator.validate(handlerMethod, request)) {
            throw new UnAuthorizedException("authorize failed");
        }
    }

}
